require('./Pagegsggmain.less');
import Reflux from 'reflux';
import ReactMixin from 'react-mixin';
import Actions from './Actions'
import Store from './Store';
import { Button,Page, Panel,PanelHeader, PanelBody, PanelFooter,ButtonArea,
  MediaBox,Cells, Cell,CellHeader,MediaBoxTitle,MediaBoxHeader,
  MediaBoxDescription,MediaBoxBody,MediaBoxInfo,MediaBoxInfoMeta,
  CellBody,CellFooter,Toast, Form,FormCell,Radio,Gallery,GalleryDelete,
  Uploader,TextArea,ActionSheet,Flex,FlexItem,SearchBar,PullToRefresh} from  'react-weui/build/packages'
import {Control} from 'react-keeper';
import tushen  from './../../../assets/icon/zhzj/图审.png';
import shigong  from './../../../assets/icon/zhzj/施工许可查询.png';
import zhaobiao  from './../../../assets/img/招标公告.png';
import zhongbiao  from './../../../assets/img/中标公告.png';
import hetong  from './../../../assets/img/合同备案.png';


class Gsggmain extends React.Component {

  constructor(props) {
    super(props);
    this.handleSubmit=this.handleSubmit.bind(this);
    this.handleCancel=this.handleCancel.bind(this);
    this.refreshData=this.refreshData.bind(this);
  }

  handleSubmit(text){
    Actions.handleSubmit(text);
  }

  handleCancel(){
    Actions.handleCancel();
  }

  refreshData(resolve){
    Actions.refreshData(resolve);
  }

  render() {
    return (
      <div>
        <SearchBar onChange={this.handleSubmit}
                   onCancel={this.handleCancel}
                   defaultValue={this.state.gsggmain.searchText}
                   placeholder="搜索工程"
        >

        </SearchBar>

        {
          this.state.gsggmain.searchDivShow&&this.state.gsggmain.searchData.length > 0&&
          <div className="searchDisDiv" onClick={this.handleCancel}>
            <Panel>
              <PanelBody>
                {this.state.gsggmain.pdata.map((item,i)=>{
                  return (
                    <MediaBox type="appmsg" onClick={() =>
                    {Control.go('/gsgghome/gsggdetail',{dataDetail:item,
                      domain:this.state.gsggmain.domain,
                      mediaUploadPath:this.state.gsggmain.mediaUploadPath
                    })}}>
                      <MediaBoxHeader>
                        <img src={item.suggesttype==1?tushen:
                          item.suggesttype==2?shigong:
                            item.suggesttype==3?zhaobiao:
                              item.suggesttype==4?zhongbiao:
                                item.suggesttype==5?hetong:null} style={{
                          width:30,
                          height:30,
                          marginTop:15
                        }}/>
                      </MediaBoxHeader>
                      <MediaBoxBody>
                        <MediaBoxTitle>{item.suggesttype==1?"图审":
                          item.suggesttype==2?"施工许可证":
                            item.suggesttype==3?"招标公告":
                              item.suggesttype==4?"中标公告":""}</MediaBoxTitle>
                        <MediaBoxDescription>
                          {item.createTime}<br/>
                          <span className="pname">{item.title}</span>
                        </MediaBoxDescription>
                      </MediaBoxBody>
                    </MediaBox>
                  )
                })
                }

              </PanelBody>
            </Panel>
          </div>
        }
        {
          this.state.gsggmain.pdata.code=="200"?
            <PullToRefresh height={window.innerHeight-44} onRefresh={this.refreshData}>
            <Panel>
              <PanelBody>
                <MediaBox key={0} type="appmsg" onClick={() =>
                {Control.go('/gsgghome/gsggdetail',
                  {
                    dataDetail:this.state.gsggmain.pdata.sgts,
                    dataType:1
                  })}}>
                  <MediaBoxHeader>
                    <img src={tushen} style={{
                      width:30,
                      height:30,
                      marginTop:15
                    }}/>
                  </MediaBoxHeader>
                  <MediaBoxBody>
                    <MediaBoxTitle>
                      图审
                    </MediaBoxTitle>
                    <MediaBoxDescription>
                      {null!=this.state.gsggmain.pdata.sgts?this.state.gsggmain.pdata.sgts.time:"--"}<br/>
                      <span className="pname">{null!=this.state.gsggmain.pdata.sgts?
                        this.state.gsggmain.pdata.sgts.xmmc:"--"}</span>
                    </MediaBoxDescription>
                  </MediaBoxBody>
                </MediaBox>
              </PanelBody>
              <PanelFooter onClick={() =>{Control.go("/gsgghome/gsgglist",1)}}>
                <Cell access link>
                  <CellBody>查看更多</CellBody>
                  <CellFooter />
                </Cell>
              </PanelFooter>
            </Panel>

            <Panel>
              <PanelBody>
                <MediaBox key={1} type="appmsg" onClick={() =>
                {Control.go('/gsgghome/gsggdetail',
                  {
                    dataDetail:this.state.gsggmain.pdata.sgxk,
                    dataType:2
                  }
                )}}>
                  <MediaBoxHeader>
                    <img src={shigong} style={{
                      width:30,
                      height:30,
                      marginTop:15
                    }}/>
                  </MediaBoxHeader>
                  <MediaBoxBody>
                    <MediaBoxTitle>
                      施工许可证
                    </MediaBoxTitle>
                    <MediaBoxDescription>
                      {null!=this.state.gsggmain.pdata.sgxk?this.state.gsggmain.pdata.sgxk.time:"--"}<br/>
                      <span className="pname">{null!=this.state.gsggmain.pdata.sgxk?
                        this.state.gsggmain.pdata.sgxk.xmmc:"--"}</span>
                    </MediaBoxDescription>
                  </MediaBoxBody>
                </MediaBox>
              </PanelBody>
              <PanelFooter onClick={() =>{Control.go("/gsgghome/gsgglist",2)}}>
                <Cell access link>
                  <CellBody>查看更多</CellBody>
                  <CellFooter />
                </Cell>
              </PanelFooter>
            </Panel>

            <Panel>
              <PanelBody>
                <MediaBox key={2} type="appmsg" onClick={() =>
                {Control.go('/gsgghome/gsggdetail',{
                  dataDetail:this.state.gsggmain.pdata.zbgg,
                  dataType:3
                })}}>
                  <MediaBoxHeader>
                    <img src={zhaobiao} style={{
                      width:30,
                      height:30,
                      marginTop:15
                    }}/>
                  </MediaBoxHeader>
                  <MediaBoxBody>
                    <MediaBoxTitle>
                      招标公告
                    </MediaBoxTitle>
                    <MediaBoxDescription>
                      {null!=this.state.gsggmain.pdata.zbgg?
                        this.state.gsggmain.pdata.zbgg.time:"--"}<br/>
                      <span className="pname">{null!=this.state.gsggmain.pdata.zbgg?
                        this.state.gsggmain.pdata.zbgg.xmmc:"--"}</span>
                    </MediaBoxDescription>
                  </MediaBoxBody>
                </MediaBox>
              </PanelBody>
              <PanelFooter onClick={() =>{Control.go("/gsgghome/gsgglist",3)}}>
                <Cell access link>
                  <CellBody>查看更多</CellBody>
                  <CellFooter />
                </Cell>
              </PanelFooter>
            </Panel>

            <Panel>
              <PanelBody>
                <MediaBox key={2} type="appmsg" onClick={() =>
                {Control.go('/gsgghome/gsggdetail',{
                  dataDetail:this.state.gsggmain.pdata.db,
                  dataType:4
                })}}>
                  <MediaBoxHeader>
                    <img src={zhongbiao} style={{
                      width:30,
                      height:30,
                      marginTop:15
                    }}/>
                  </MediaBoxHeader>
                  <MediaBoxBody>
                    <MediaBoxTitle>
                      中标公告
                    </MediaBoxTitle>
                    <MediaBoxDescription>
                      {null!=this.state.gsggmain.pdata.db?
                        this.state.gsggmain.pdata.db.time:"--"}<br/>
                      <span className="pname">{this.state.gsggmain.pdata.db.xmmc}</span>
                    </MediaBoxDescription>
                  </MediaBoxBody>
                </MediaBox>
              </PanelBody>
              <PanelFooter onClick={() =>{Control.go("/gsgghome/gsgglist",4)}}>
                <Cell access link>
                  <CellBody>查看更多</CellBody>
                  <CellFooter />
                </Cell>
              </PanelFooter>
            </Panel>

            <Panel>
              <PanelBody>
                <MediaBox key={2} type="appmsg" onClick={() =>
                {Control.go('/gsgghome/gsggdetail',{
                  dataDetail:this.state.gsggmain.pdata.ht,
                  dataType:5
                })}}>
                  <MediaBoxHeader>
                    <img src={hetong} style={{
                      width:30,
                      height:30,
                      marginTop:15
                    }}/>
                  </MediaBoxHeader>
                  <MediaBoxBody>
                    <MediaBoxTitle>
                      合同备案
                    </MediaBoxTitle>
                    <MediaBoxDescription>
                      {null!=this.state.gsggmain.pdata.ht?
                        this.state.gsggmain.pdata.ht.time:"--"}<br/>
                      <span className="pname">{null!=this.state.gsggmain.pdata.ht?
                        this.state.gsggmain.pdata.ht.xmmc:"--"}</span>
                    </MediaBoxDescription>
                  </MediaBoxBody>
                </MediaBox>
              </PanelBody>
              <PanelFooter onClick={() =>{Control.go("/gsgghome/gsgglist",5)}}>
                <Cell access link>
                  <CellBody>查看更多</CellBody>
                  <CellFooter />
                </Cell>
              </PanelFooter>
            </Panel>
          </PullToRefresh>
            :
            <Panel>
              <PanelBody>
                <MediaBox>没有数据</MediaBox>
              </PanelBody>
            </Panel>
        }
      </div>
    );
  }

  componentWillMount() {
    Actions.loadData();
  }

  componentDidMount() {

  }

  componentWillReceiveProps(nextProps) {

  }

  shouldComponentUpdate(nextProps, nextState) {
    const thisProps = this.props || {},
      thisState = this.state.gsggmain || {};
    if (Object.keys(thisProps).length !== Object.keys(nextProps).length ||
      Object.keys(thisState).length !== Object.keys(nextState).length) {
      return true;
    }

    for (const key in nextProps) {
      if (thisProps[key] !== nextProps[key]) {
        console.log(thisProps[key], nextProps[key]);
        return true;
      }
    }

    for (const key in nextState) {
      if (thisState[key] !== nextState[key]) {
        return true;
      }
    }
    return false;
  }

}

ReactMixin.onClass(Gsggmain, Reflux.connect(Store, 'gsggmain'));


export default Gsggmain ;
